package com.services;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import model.Movie;

@Stateless
public class MoviesService {

	@PersistenceContext(unitName = "cinema-unit")
	private EntityManager em;
	
	public List<Movie> getAllMovies() {
		Query q = em.createNamedQuery("Movie.findAll");
		List<Movie> result = q.getResultList();

		return result;
	}
	
	public Movie getMovieById(int id) {

		return em.find(Movie.class, id);

	}
	
}
